﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace BllFactory
{
   public class ServiceFactory
    {
       public static T CreatService<T>()
       {
           //根据配置文件拿到指定的程序集  
           string bllName = ConfigurationManager.AppSettings["BllName"];
           Assembly asse = Assembly.Load(bllName);
           Type[] types = asse.GetTypes();
           object service = null;
           foreach (Type t in types)
           {
               if (typeof(T).IsAssignableFrom(t))
               {
                   service = Activator.CreateInstance(t);
                   break;
               }
           }
           return (T)service;
       }
    }
}
